package com.heima.article.service.impl;

import com.heima.article.mapper.ApArticleMapper;
import com.heima.article.service.ApArticleService;
import com.heima.model.article.dto.ArticleHomeDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.common.dtos.ResponseResult;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ApArticleServiceImpl implements ApArticleService {

    @Autowired
    private ApArticleMapper apArticleMapper;

    /**
     * 文章 展示
     *
     * @param articleHomeDto
     * @param type
     * @return
     */
    @Override
    public ResponseResult loads(ArticleHomeDto articleHomeDto, Integer type) {

        // 1、校验数据
        if (articleHomeDto.getSize() == null){
            articleHomeDto.setSize(10);
        }

        if (articleHomeDto.getTag() == null){
            articleHomeDto.setTag("__all__");
        }

        if (articleHomeDto.getMinBehotTime() == null){
            articleHomeDto.setMinBehotTime(new Date());
        }

        if (articleHomeDto.getMaxBehotTime() == null){
            articleHomeDto.setMaxBehotTime(new Date());
        }

        // 2、调用接口
        List<ApArticle> articleList = apArticleMapper.loads(articleHomeDto, type);

        // 封装 数据 返回结果
        return ResponseResult.okResult(articleList);
    }
}
